package com.quxiu.system.constant;

import com.quxiu.common.core.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;

import java.util.Arrays;
import java.util.List;

/**
 * 推送数据类型
 */
public enum PushDataType {
    USER("user", "用户数据"),
    DEPT("dept", "部门数据"),
    ;

    private String code;
    private String desc;

    PushDataType(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static boolean contains(String sourceStr, PushDataType type) {
        if (StringUtils.isBlank(sourceStr)) {
            return false;
        }
        List<String> source = Arrays.asList(sourceStr.split(","));
        return contains(source, type);
    }

    public static boolean contains(List<String> source, PushDataType type) {
        if (CollectionUtils.isEmpty(source)) {
            return false;
        }
        if (type == null) {
            return false;
        }
        return source.contains(type.getCode());
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }
}
